package com.zuo.model;

import java.io.Serializable;
import java.util.Objects;

/**
 * @Author 白白旧维
 * @Date 2022/3/15 11:29
 */
public class MyResponse<T> implements Serializable {

    private Integer code;

    private String message;

    private T result;

    public MyResponse() {
    }

    public MyResponse(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public MyResponse(Integer code, String message, T result) {
        this.code = code;
        this.message = message;
        this.result = result;
    }

    public static MyResponse success(){
        return new MyResponse(0,"成功");
    }

    public static <T> MyResponse success(T result){
        return new MyResponse(0,"成功",result);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MyResponse<?> that = (MyResponse<?>) o;
        return Objects.equals(code, that.code) &&
                Objects.equals(message, that.message) &&
                Objects.equals(result, that.result);
    }

    @Override
    public int hashCode() {
        return Objects.hash(code, message, result);
    }

    @Override
    public String toString() {
        return "MyResponse{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", result=" + result +
                '}';
    }
}
